#include<bits/stdc++.h>

using namespace std;

vector<pair<string,int> > ser;
int n;

int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		string op,ad;
		cin>>op>>ad;
		bool right=1,z=0,m=0;
		int num=0,cnt=0,mmax=255;
		for(int j=0;j<ad.size();j++){
			if(ad[j]=='0'){
				if(z){
					right = 0;
					break;
				}
				if(num==0){
					z = 1;
				}
				else{
					num*=10;
				}
			}
			else if(ad[j]>='1'&&ad[j]<='9'){
				if(z){
					right = 0;
					break;
				}
				num*=10;
				num+=(ad[j]-'0');
			}
			else if(ad[j]=='.'){
				if(num==0&&z==0){
					right = 0;
					break;
				}
				z = 0;
				cnt++;
				if(cnt>3){
					right = 0;
					break;
				}
				num = 0;
			}
			else if(ad[j]==':'){
				if(num==0&&z==0){
					right = 0;
					break;
				}
				z = 0;
				m = 1;
				cnt++;
				if(cnt!=4){
					right = 0;
					break;
				}
				num = 0;
				mmax=65535;
			}
			else{
				right = 0;
				break;
			}
			if(num>mmax){
				right = 0;
				break;
			}
		}
		if(num==0&&z==0){
			right = 0;
		}
		if(num>mmax){
			right = 0;
		}
		if(right==0||m!=1){
			cout<<"ERR"<<endl;
			continue;
		}
		if(op=="Client"){
			bool flag=0;
			for(int j=0;j<ser.size();j++){
				if(ad==ser[j].first){
					cout<<ser[j].second<<endl;
					flag = 1;
					break;
				}
			}
			if(!flag){
				cout<<"FAIL"<<endl;
			}
		}
		else{
			bool flag=1;
			for(int j=0;j<ser.size();j++){
				if(ad==ser[j].first){
					flag = 0;
					break;
				}
			}
			if(flag){
				ser.push_back(make_pair(ad,i));
				cout<<"OK"<<endl;
			}
			else{
				cout<<"FAIL"<<endl;
			}
		}
	} 
	return 0;
}
